<?php
class DataCompanyDepartmentAction extends CommonAction {
    
    protected $_str_model           = 'DataCompanyDepartment';
    protected $_arr_search          = array(
                                            'company_id'       => array('LIKE', '%?%', 'int'),
                                            'company_name'     => array('LIKE', '%?%', 'str'),
                                            'department_id'    => array('LIKE', '%?%', 'int'),
                                            'department_name'  => array('LIKE', '%?%', 'str'),
                                            'level'            => array('EQ', '?', 'int'),
                                            'display_order'    => array('EQ', '?', 'int'),
                                            'remark'           => array('LIKE', '%?%', 'str'),
                                            'status'           => array('EQ', '?', 'int'),
                                      );
                                      
    /**
     * Set params
     * global settings, for index, edit, add
     *
     * @param  void
     * @return void
     * @author andy
     */
    public function set_params() {

        $this->assign('arr_level', get_range_array(0, 10));
        $this->assign('arr_display_order', get_range_array());
    }
    
    /**
     * Search before
     * 
     * @param  void
     * @return void
     * @author andy
     */
    public function before_search() {

        if ( ! $this->_post('company_id') ) {
            set_post('company_id', D('DataCompanyBasic')->get_pk_by_name($this->_post('company_name'), 'company_name'), false);
        }
    }
    
    /**
     * Before do action
     * for edit, add
     * 
     * @param  void
     * @return void
     * @author andy
     */
    public function before_do_action() {

        set_post('company_id', $this->_post('data_company_basic_company_id'), false);
        set_post('parent_department_id', $this->_post('data_company_department_department_id'), false);
        set_post('level', $this->_post('data_company_department_level') + 1, false);
    }
}